import * as ajax from "../../common/ajax";

export const get = id => ajax.get("/admin/course/" + id);

export const create = entity => ajax.post("/admin/course", entity);

export const deleteItem = id => ajax.pureDelete("/admin/course/" + id);

export const update = entity => ajax.put("/admin/course", entity);

export const getPageCount = (departmentName, majorName, name) =>
  ajax.get("/admin/course/page/count", {
    departmentName: departmentName,
    majorName: majorName,
    name: name
  });

export const getPage = (index, departmentName, majorName, name) =>
  ajax.get("/admin/course/page/" + index, {
    departmentName: departmentName,
    majorName: majorName,
    name: name
  });

export const listName = () => ajax.pureGet("/admin/course/names");

export const pageSize = 20;

// 获取待审核课程列表
export const getPendingCourses = () => ajax.pureGet("/admin/course/pending");

// 审核课程
export const auditCourse = (courseId, approved) => ajax.post("/admin/course/audit?courseId="+courseId+"&approved="+approved);

// 获取所有课程列表
export const getList = () => ajax.pureGet("/admin/course/list");

// 创建课程
export const createCourse = course => ajax.post("/admin/course/create", course);

// 更新课程
export const updateCourse = course => ajax.post("/admin/course/update", course);

// 删除课程
export const removeCourse = id => ajax.post("/admin/course/delete", { id });

export default {
  pageSize,
  getPage,
  get,
  create,
  update,
  delete: deleteItem,
  listName,
  auditCourse(id, approved) {
    return ajax.post("/admin/course/" + id + "/audit", { approved });
  }
}
